<template>
  <div>
    <el-dropdown @command="commendEvent">
      <span style="color:#fff;">
        <svg-icon iconClass="language"></svg-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="en" :disabled="$i18n.locale === 'en'"
            >English</el-dropdown-item
          >
          <el-dropdown-item command="zh" :disabled="$i18n.locale === 'zh'"
            >中文</el-dropdown-item
          >
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
<script>
import jsCookie from 'js-cookie'
// jsCookie.get(key)   jsCookie.set(key,value)  jsCookie.remove(key)
export default {
  name: 'Lang',
  inject: ['reload', 'fn'],
  methods: {
    commendEvent (command) {
      // 切换i18n语言
      this.$i18n.locale = command
      //   本地存储国际化语言
      jsCookie.set('lang', command)
      //   刷新：
      //   this.$router.go(0)
      //   this.that.reloadFn()
      this.fn(Date.now())
      //   调用injext方法刷新页面
      this.reload()
      //   switch (command) {
      //     case 'en':
      //         this.$i18n.locale='en'
      //       break
      //     case 'zh':
      //       break
      //   }
    }
  }
}
</script>
<style></style>
